<template>
  <!-- banner下导航部分 -->
  <div class="cate">
    <router-link
      v-for="cate in cateData.slice(0,5)"
      :key="cate.id"
      class="cate-item"
      tag="div"
      :to="'/cate?id=' + cate.id"
      @mouseover.native="over(cate)"
      @mouseleave.native="leave(cate)"
    >
      <img
        :src="cate.isSelected ? cate.AdfullImageUrl : cate.fullImageUrl"
        alt=""
      >
      <span class="name">{{ cate.cName }}</span>
      <span class="button">点击选购</span>
    </router-link>
  </div>
</template>

<script>
import defaultImg from "../../assets/img/classify1.png";
// import activeImg from "../../assets/img/classify2.png"
export default {
  name: "",
  components: {},
  data() {
    return {
      cateData: [
        {
          img: defaultImg,
          name: "优鲜水果",
          id: 1,
        },
        {
          img: defaultImg,
          name: "优鲜水果",
          id: 2,
        },
        {
          img: defaultImg,
          name: "优鲜水果",
          id: 3,
        },
        {
          img: defaultImg,
          name: "优鲜水果",
          id: 4,
        },
        {
          img: defaultImg,
          name: "优鲜水果",
          id: 5,
        },
      ],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$api.home.getClasses().then((res) => {
        if (res.code == 200) {
          this.cateData = res.data;
          // console.log("cateData", this.cateData);
        }
      });
    },
    over(item) {
      item.isSelected = true;
    },
    leave(item) {
      item.isSelected = false;
    },
  },
};
</script>

<style scoped lang="scss">
.cate {
  // width: 100%;
  padding: 0 10rem;
  margin-top: 7.81rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .cate-item:first-child{
    margin-left: 0;
  }
  .cate-item {
    width: 20%;
    height: 17rem;
    background: rgba(255, 255, 255, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 1rem;
    
    img {
      width: 6.75rem;
      height: 4.88rem;
      object-fit: contain;
    }
    .name {
      font-size: 1.13rem;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(102, 102, 102, 1);
      margin-top: 1.13rem;
    }
    .button {
      width: 4.75rem;
      height: 1.44rem;
      background: rgba(0, 209, 169, 1);
      text-align: center;
      display: inline-block;
      margin-top: 0.94rem;
      line-height: 1.44rem;
      font-size: 0.88rem;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(255, 255, 255, 1);
    }
    &:hover {
      background: #00d1a9;
      .name {
        color: #ffffff;
      }
      .button {
        background: #ffffff;
        color: #00d1a9;
      }
    }
  }
}
</style>
